package com.hxkcloud.patient.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hxkcloud.patient.R;
import com.hxkcloud.patient.beans.ArticleKindBean;

import java.util.List;

/**
 * Created by ray_lei on 2016/7/6.
 */
public class IvgTextAdapter extends RecyclerView.Adapter<ViewHolder> {


    private Context mContext;
    private List<ArticleKindBean> datas;
    private LayoutInflater mInflater;

    private ResultSelectedListener listener;

    public IvgTextAdapter(Context mContext, List<ArticleKindBean> datas, ResultSelectedListener listener) {
        this.mContext = mContext;
        this.datas = datas;
        this.listener = listener;
        mInflater = LayoutInflater.from(mContext);
    }

    public void setData(List<ArticleKindBean> datas) {
        this.datas = datas;
        notifyDataSetChanged();
    }

    public void clearData() {
        datas.clear();
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        // TODO Auto-generated method stub
        return datas.size();
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        // TODO Auto-generated method stub


        Holder mHolder = (Holder) holder;

        mHolder.nameTV.setText(datas.get(position).getName());
        mHolder.nameTV.setSingleLine(true);

        if (datas.get(position).isSelected()) {
            mHolder.nameTV.setTextColor(mContext.getResources().getColor(R.color.light_blue));
            mHolder.kindIV.setImageResource(R.mipmap.tab_arrow_pre);
        } else {
//            if (datas.get(position).isSelecting()) {
//                mHolder.nameTV.setTextColor(mContext.getResources().getColor(R.color.light_blue));
//                mHolder.kindIV.setImageResource(R.mipmap.tab_arrow_s);
//            }else{
            mHolder.nameTV.setTextColor(mContext.getResources().getColor(R.color.black_text));
            mHolder.kindIV.setImageResource(R.mipmap.tab_arrow);
//            }
        }


        mHolder.layout.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                listener.onSelected("click", position);

            }

        });


    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {


        View v = mInflater.inflate(R.layout.item_text_layout, null);
        ViewHolder holer = new Holder(v);

        return holer;
    }

    @Override
    public int getItemViewType(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    /*
     * Holder
     */
    public class Holder extends ViewHolder {

        LinearLayout layout;
        TextView nameTV;
        ImageView kindIV;


        public Holder(View view) {
            super(view);
            layout = (LinearLayout) view.findViewById(R.id.news_item_layout_kind);
            nameTV = (TextView) view.findViewById(R.id.news_item_tv_kind);
            kindIV = (ImageView) view.findViewById(R.id.news_item_iv_kind);

        }
    }

    public interface ResultSelectedListener {
        void onSelected(String type, int position);
    }


}
